!{include file='common/header.htm'}
<link rel="stylesheet" href="/template/js/editor/kindEditor/themes/default/default.css" />
<script src="/template/js/editor/kindEditor/kindeditor-min.js"></script>
<script src="/template/js/editor/kindEditor/lang/zh_cn.js"></script>
<script src="!{res file='js/jquery_plus/jquery.form.js'}"></script>
<div class="main_content wrap" id="main_content">
	<div class="left_content" id="wiki_edit_content">
		<h1><a href="/wiki/!{$wiki.word}">!{$wiki.word}</a></h1>
		<form id="wiki_form" action="/wiki/edit_item" method="post"  enctype="multipart/form-data">
			!{include file='./_edit_item.htm'}
			<div class="center opt_div">
				<input type="hidden" value="!{$wiki.word}" name="q"/>
				<input type="submit" value="保存" class="btn"/>
				<input type="button" value="返回" class="btn" onclick="window.location.href='/wiki/!{$wiki.word}'"/>
			</div>
		</form>
	</div>
	<div class="right_content wiki_ext_info">
		<a href="/wiki/add"><img src="!{res file='template/wiki/images/add_word.jpg'}" alt="添加词条"/></a>
		!{include file='./_history.htm'}
		!{include file='./_word_index.htm'}
		!{include file='./_creator.htm'}
		!{include file='./_contributors.htm'}
	</div>
</div>
<script src='!{res file="js/jquery_plus/jquery.validate.min.js"}'></script>
<script>
	function onUploadSuccess(file, data){

	}
	
	$(function(){
		$('.tabs').tabs();
		$('.btn').button();
		$('.auto_img').auto_img();
		KindEditor.create('.wysiwyg', {
			items : [
		         "undo", "redo", "|", "preview", "print", "template", "cut", "copy", "paste",
		         "plainpaste", "wordpaste", "|", "justifyleft", "justifycenter", "justifyright",
		         "justifyfull", "insertorderedlist", "insertunorderedlist", "indent", "outdent", "subscript",
		         "superscript", "clearhtml", "quickformat", "selectall", "|", "fullscreen",
		         "formatblock", "fontname", "fontsize", "|", "forecolor", "hilitecolor", "bold",
		         "italic", "underline", "strikethrough", "lineheight", "removeformat", "|", "image",
		         "flash", "media", "insertfile", "table", "hr", "emoticons", "map", "code", "pagebreak",
		         "link", "unlink" 
	         ],
         	syncType:'form',
         	afterBlur:function(){
				this.sync();
			},
			afterCreate:function(){
				$(this.container).removeAttr("style");
			},
			cssPath : "/template/js/editor/kindEditor/plugins/code/prettify.css",
			uploadJson : "/index.php?app=site&act=upload",
			//fileManagerJson : "/index.php?app=site&act=file_manager",
			allowFileManager : false
		});
		
		!{if !$item_title}
		$('#wiki_form').validate({
			rules : {
				p : {
					required : true,
					remote : {
						url : '/wiki/check_word_index/',
						type : 'post',
						data : {
							word : '!{$wiki.word}',
							index : function(){return $('#index_input').val();}
						}
					}
				},
			},
			messages : {
				p : {
					required : '词条目录不能为空',
					remote : '词条目录已经存在！'
				},
			}
		});
		!{/if}
		
		//添加相关词条
		$('#add_refer').click(function(){
			var word = $('input[name="refer_word"]').val();
			word = word.trim();
			if(word.length == 0){
				alert('不能添加空的关联词条！');
				return;
			}
			if(word == '!{$wiki.word}'){
				alert('不能添加自己！');
			}
			$.post('/wiki/add_refer', {
				word:word
			}, function(data){
				var json = eval('(' + data + ')');
				if(json.result){
					//添加成功
					$('.no_refer').remove();
					$('#refer_words').append('<li>' + word + '<input type="hidden" name="refers[]" value="' + word + '"/> <input type="button" value="删除" onclick="$(this).parent().remove();"/></li>');
				}else{
					//添加失败
					alert(json.info);
				}
			});
		});
	});
	var WORD = '!{$wiki.word}';
</script>
!{include file='common/footer.htm'}